package com.ym.controller.patient.self;

import com.github.pagehelper.PageInfo;
import com.ym.common.constant.Constants;
import com.ym.core.annotation.ApiSign;
import com.ym.core.annotation.Log;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;
import com.ym.core.shiro.ShiroUtil;
import com.ym.medical.domain.entity.ComplainRecordEntity;
import com.ym.medical.domain.vo.DoctorVo;
import com.ym.medical.enums.ComplainStateEnum;
import com.ym.medical.service.IComplainRecordSV;
import com.ym.medical.service.IPatientCenterSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author: 张文博
 * @version: 2019年05月10日 17:32
 */
@Api("个人中心")
@Controller
@ApiSign
@RequestMapping(value = "patient/self/doctor", headers = Constants.Api.VERSION)
public class MyDoctorController extends BaseController {

	@Autowired
	private IPatientCenterSV iPatientCenterSV;

	@Autowired
	private IComplainRecordSV complainRecordSV;

	@Log(dataBase = false, printBody = false)
	@ApiOperation("我的医生")
	@GetMapping(value = "/selectMyDoctor")
	@ResponseBody
	public APIResponse<Map<String, Object>> selectMyDoctor(
			@ApiParam(name = "pageNo", value = "页码", required = true)
			@RequestParam(name = "pageNo", required = true, defaultValue = "1")
					int pageNo,
			@ApiParam(name = "pageSize", value = "每页数量", required = false)
			@RequestParam(name = "pageSize", required = false, defaultValue = "10")
					int pageSize) throws Exception {
		Long paId = ShiroUtil.getLoginId();
		//Long paId = 1L;
		Map<String, Object> map = new HashMap<>();
		//我关注的医生
		PageInfo<DoctorVo> myFocus = iPatientCenterSV.selectMyDoctor(pageNo, pageSize, paId);
		//List<DoctorVo> myFocus = iPatientCenterSV.selectMyDoctor(paId);
		map.put("myFocus", myFocus);
		//map.put("inquiryDoctor",myFocus);
		return successData(map);
	}

	@Log
	@ApiOperation("患者提交申诉工单")
	@PostMapping(value = "/complain/insert", consumes = MediaType.APPLICATION_JSON_VALUE)
	public APIResponse refundComplain(@RequestBody ComplainRecordEntity complainRecord) {
		complainRecord.setState(ComplainStateEnum.IN_THE_REVIEW.getKey());
		complainRecord.setComplainPerson(ShiroUtil.getLoginId());
		complainRecord.setCreateTime(new Date());
		complainRecordSV.insert(complainRecord);
		return failMsg("患者提交申诉工单成功");
	}
}
